package cn.edu.Day06.service.Impl;

import cn.edu.Day06.Entity.Enemy;
import cn.edu.Day06.GameFrame;
import cn.edu.Day06.service.EnemyService;

import java.awt.*;
import java.util.List;
import java.util.Random;

public class EnemyServiceImpl implements EnemyService {

    @Override
    public void createEmemies(List<Enemy> enemies, Random ran) {
        Enemy enemy = new Enemy();
        enemy.setY(0-enemy.getHeight());
        enemy.setX(ran.nextInt(GameFrame.W));
        enemies.add(enemy);

    }

    @Override
    public void drawEnemies(Graphics g, List<Enemy> enemies) {
        if (enemies.size()>0){
            for (int i = 0; i < enemies.size(); i++) {
                Enemy e = enemies.get(i);
                g.drawImage(Enemy.IMG,e.getX(),e.getY(),e.getWidth(),e.getHeight(),null);
            }
        }

    }

    @Override
    public void down(List<Enemy> enemies) {
        if (enemies.size()>0){
            for (int i = 0; i < enemies.size(); i++) {
                Enemy e = enemies.get(i);
                e.setY(e.getY()+e.getSpeed());
            }
        }

    }
}
